﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyModel;
using NetMicro.Core.Extensions;

namespace NetMicro.EventBus.Extensions
{
    /// <summary>
    /// 反射扩展
    /// </summary>
    public static class ReflectionExtensions
    {

        /// <summary>
        /// 获取所有的子类和自身,不包括接口和抽象类,包含泛型定义
        /// </summary>
        /// <param name="baseType">基类,可以是泛型定义</param>
        /// <param name="dependencyContext"></param>
        /// <returns></returns>
        public static List<Type> GetFinalSubTypes(this IEnumerable<Type> types, Type type)
        {
            return types.Where(r =>
                  !r.IsAbstract && r.IsClass && (r.IsBaseOn(type) || r.IsSubclassOfGeneric(type))).ToList();
        }



    }
}
